<?php
// +----------------------------------------------------------------------
// | KITEGO-Admin「开箱即用」「人人全栈」
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.kitego.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed KITEGO并不是自由软件，未经许可不能去掉KITEGO相关版权
// +----------------------------------------------------------------------
// | Author: KITEGO Team <bd@kitego.cn>
// +----------------------------------------------------------------------

namespace app\adminapi\controller\v1\setting;

use app\adminapi\services\setting\SystemMenuService;
use Exception;
use kitego\base\BaseController;
use think\App;
use think\response\Json;

class SystemMenuController extends BaseController
{
    private SystemMenuService $service;

    public function __construct(App $app, SystemMenuService $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }

    /**
     * 获取系统菜单
     * @throws Exception
     */
    public function getSystemMenu(): Json
    {
        return $this->service->getSystemMenu();
    }

    /**
     * 菜单列表
     */
    public function listSystemMenu(): Json
    {
        return $this->service->listSystemMenu($this->params);
    }

    /**
     * 编辑菜单
     */
    public function editSystemMenu(): Json
    {
        $param = $this->params;
        // pid空则顶级菜单
        if (empty($param['pid'])) {
            $param['pid'] = 0;
        }
        return $this->service->editSystemMenu($param);
    }

    /**
     * 删除菜单
     */
    public function delSystemMenu(): Json
    {
        return $this->service->delSystemMenu(req_decode());
    }

    /**
     * 排序菜单
     */
    public function sortSystemMenu(): Json
    {
        return $this->service->sortSystemMenu(req_decode());
    }
}